﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using MSAcademic.v2.Infrastructure.Article;
using MSAcademic.v2.Infrastructure.Tag;
using MSAcademic.v2.Infrastructure.User;

namespace MSAcademic.v2.Web.Models
{
    // TODO: Dodati kolekciju zadnjih autorovih članaka s tagovima
    public partial class AuthorViewModel
    {
        public int AuthorId { get; set; }
    }
    public partial class AuthorViewModel
    {
        public IUser Author
        {
            get
            {
                if (_author == null)
                {
                    _author = new Lazy<IUser>(() => _userQueries.TryGetWhereId(AuthorId));
                }
                return _author.Value;
            }
        }

        public IEnumerable<IArticle> AuthorsArticles
        {
            get
            {
                if (_authorsArticles == null)
                {
                    _authorsArticles = new Lazy<IEnumerable<IArticle>>(() => _articleQueries.GetArticlesWrittenByAuthor(AuthorId, false));
                }
                System.Diagnostics.Debug.WriteLine(_authorsArticles.Value);
                return _authorsArticles.Value;
            }
        }

        private Lazy<IUser> _author;
        private Lazy<IEnumerable<IArticle>> _authorsArticles; 
    }
    public partial class AuthorViewModel
    {
        private readonly IArticleQueries _articleQueries ;
        private readonly ITagQueries _tagQueries;
        private readonly IUserQueries _userQueries;
        public AuthorViewModel(IArticleQueries articleQueries, /*ITagQueries tagQueries,*/ IUserQueries userQueries)
        {
            //_tagQueries = tagQueries;
            _articleQueries = articleQueries;
            _userQueries = userQueries;
        }
    }
}